var c=require('../lib/common.js');
var time=require('../lib/time-set.js');
var cf = require('../lib/config.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dbimgurl: '/images/tu.png',
    pname: '立即开始',
    money: 5,
    total_price: 5,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var selecttimen = parseInt(Number(new Date() / 1000));//当天时间戳
    this.setData({ selecttimen: selecttimen })
    time.settime(this, this.data.pname);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  //图片上传
  tuup: function () {
    c.tuup(this);
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  beizhu: function (e) {
    var value = e.detail.value;
    this.setData({
      beizhu: value
    })
  },
  //取货时间确定
  bindMultiPickerChange(e) {
    time.bindMultiPickerChange(e, this);
  },
  //获取时间选择
  bindMultiPickerColumnChange(e) {
    time.bindMultiPickerColumnChange(e, this, this.data.pname);
  },
  //确定
  submit: function () {
    wx.showLoading({
      title: '提交订单...',
    })
    var integral = this.data.integral;
    var uid = wx.getStorageSync('userinfo').id;
    var selecttime = this.data.selecttime;
    time.setselecttime(selecttime, this);
    var selecttimen = this.data.selecttimen;
    var id = this.data.id;//一级菜单
    var tid = this.data.tid;//一级菜单
    var beizhu = this.data.beizhu == undefined ? '暂无' : this.data.beizhu; //备注
    var imgid = this.data.imgid == undefined ? '' : this.data.imgid;//图片id
    var total_price = this.data.total_price;//总价钱
    var price = this.data.price;//服务费
    c.ajax(
      cf.hostapi + 'createOrder',
      { cate_1_id: id, cate_2_id: tid, ramark: beizhu, images: imgid, total_price: total_price, price: price, statr_time: selecttimen, uid: uid, integral: integral },
      res => {
        var order_id = res.data.data;
        if (res.data.retcode == 200) {
          wx.hideLoading();
          wx.showToast({
            title: '生成订单成功',
            image: '/images/dui.png'
          })

          setTimeout(function () {
            wx.redirectTo({
              url: '/pages/paynow/paynow?order_id=' + order_id,
            })
          }, 1000)

        };
      }
    )
  }
})